RCS "$Id: Lexing.sig,v 1.6 1999/07/16 17:40:43 pxs Exp $";
(* Some convenience functions.                                         *)    
(* The idea is that a structure matching this signature stores the     *)
(* currently applicable lexing function, so that it can be used by the *)
(* checking functions. Therefore it's important to know if anyone's    *)
(* sharing your lexer, and to init it as appropriate.                  *)
signature LEXING =
  sig
    include TOKENS			(* Do we really need to do this?? *)
(* Create (and store) a new lexer on the given string *)
    val initLexer : string -> unit
(* using the lexer made by initLexer, return next token *)
    val lexer : unit -> token
(* Returns the string up to but not including the matching Rbrack (to the *)
(* one we assume we've just had) *)
    val toRbrack : unit -> string
(* cache a token so that it will be returned by the next call to *)
(* lexer: a hack to allow 1 place of lookahead. *)
    val cache : token -> unit
(* The 4 checking functions raise CheckFailed if the token encountered *)
(* isn't what was expected. *Next takes one token and compares it with *)
(* the next token produced by the lexer. The others take two tokens    *)
(* and compare them. (not just)* also returns the next token after the one*)
(* on which the comparison was done. *)
    val check : token * token -> token
    val checkNext : token -> token
    val justCheck : token * token -> unit
    val justCheckNext : token -> unit
(* We sometimes want function "is Rbrack" etc. Overkill? Who cares ? :-) *)
    val is : token -> token -> bool
(* The function eats the terminating token, but doesn't put it on the string *)
    val getStringUpToNext : token -> string
(* Special case: behaves like getStringUpToNext Eos *)
(* return the unlexed portion of the string we started with (up to the *)
(* fact that lexing and then stringifying isn't quite the identity!)*)
    val getRest : unit -> string
    val toComma : unit -> string
    val toCommaWithBracketCount : unit -> string
    val stripOutsideRest : unit -> string
(* Given a way of reading a Thing, return a way of reading a Thing list. *)
(* we don't eat the brackets. Would it be better if we did? *)
    val readList : (unit -> 'a) -> (unit -> 'a list)
(* Read bracketed pair, (thing,thing). Note arguments!! *)
    val readBracketedPair : ((unit -> 'a) * (string -> 'b)) ->
      (unit -> 'a * 'b)
     
    val readString : unit -> string
    val readNat : unit -> int
    val readVar : unit -> V.var

(* parse is misnamed: it gets the command carried out, too *)      
    val parse : string -> unit
end

